
import 'package:sqflite/sqflite.dart';
import 'db_provider.dart';

//按照这个来写 https://blog.csdn.net/qq_19979101/article/details/93030803
class DaoVod extends DbProvider{

  //表名
  final String name='dg_vod';
  //表主键字段
  final String columnId='id';

  @override
  tableName(){
    return name;
  }
  //创建表
  @override
  tableSqlString() {
    return tableBaseString(name, columnId)+
        '''
    
    ''';
  }
  //插入新数据
  Future insert(Map info) async{
    Database db=await getDataBase();
    return await db.insert(name,info);
  }

  //根据ID获取一条数据
  Future<Map> getTypeById(String id) async{
    Database db=await getDataBase();
    List<Map<String,dynamic>> maps=await db.query(name,where:"id=?",whereArgs:[id]);
    if(maps.length>0){
      Map info=maps.first;
      return info;
    }
    return null;
  }

  //获取列表
  Future<List<Map>> getTypeList() async{
    Database db=await getDataBase();
    List<Map<String,dynamic>> maps=await db.query(name);
    if(maps.length>0){
      List<Map> infos=maps.map((item)=>item).toList();
      return infos;
    }
    return null;
  }
}